
import App from './App.vue'
import store from "./vuex"

// babel-polyfill 垫片
import 'babel-polyfill'
import "./css/icon/iconfont.css"

const configRouter = require('./config-router').arr
const hostConfig = require('./host.config.js').host

let G = global;
G.hide = 'hide';
G.show = 'show';
G.active = 'active';
G.current = 'current';
G.disabled = 'disabled';
G.selected = 'selected';
G.loading = 'loading';
G.payDelayTime = 2000;      // 单位毫秒
G.netErrStr = '网络错误';
G.loginStr = '需要重新登录';






Vue.filter('filterAvatar', function(n, type){     // type 默认，0   1, 头像-透明  2, 头像-白底
    if(n) return n;
    if(type == 1){
        return globalLogo;
    }
    if(type == 2){
        return globalLogoWhite;
    }
    return globalAvatar;
});

Vue.filter('filterDate', function(a, s){      // 默认-， 用于替换-  ru： 2017-10-10
    if(!a) return ;
    a = a.replace(/^(\d{4}\-\d{2}\-\d{2})\s?\d{2}:\d{2}:\d{2}$/, '$1');

    if(s){
        a = a.replace(s)
    }

    return a;
});

Vue.filter('filterQiniu', function(value, m, w, h){
    var s = '';
    if (!value) {
        return;
    }
    s += value.split(',')[0].split('?')[0] + '?imageView2/' + m + '/w/' + w;
    if(h>0){
        s += '/h/' + h;
    }
    return s;
});


/* extend - start */
var extend = function() {
    var options, name, src, copy, copyIsArray, clone;
    var target = arguments[0];
    var i = 1;
    var length = arguments.length;
    var deep = false;

    // Handle a deep copy situation
    if (typeof target === 'boolean') {
        deep = target;
        target = arguments[1] || {};
        // skip the boolean and the target
        i = 2;
    }
    if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
        target = {};
    }

    for (; i < length; ++i) {
        options = arguments[i];
        // Only deal with non-null/undefined values
        if (options != null) {
            // Extend the base object
            for (name in options) {
                src = target[name];
                copy = options[name];

                // Prevent never-ending loop
                if (target !== copy) {
                    // Recurse if we're merging plain objects or arrays
                    if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
                        if (copyIsArray) {
                            copyIsArray = false;
                            clone = src && isArray(src) ? src : [];
                        } else {
                            clone = src && isPlainObject(src) ? src : {};
                        }

                        // Never move original objects, clone them
                        target[name] = extend(deep, clone, copy);

                        // Don't bring in undefined values
                    } else if (typeof copy !== 'undefined') {
                        target[name] = copy;
                    }
                }
            }
        }
    }

    // Return the modified object
    return target;
}
G.extend = extend;
/* extend - end */

let host = location.host,

	basePreUrl = host == 'qcwww.jinghao.com' ? '//qcapi.jinghao.com' : '//apitest-sass.jinghao.com';
// api -  //jhl.jinghao.com, //jhtest.jinghao.com, //api.jinghao.com
// fel.jinghao.com:9300   fejh.jinghao.com    jhsy.jinghao.com


axios.defaults.timeout = 8000;
axios.defaults.baseURL = basePreUrl;
axios.defaults.withCredentials = true
//axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

axios.interceptors.response.use(function(a) {
    if (a.status === 200) {
        if (a.data.flag === -100) {
            var lA = document.createElement('a');
            
	        window.location.assign('/register/introduce')
            //lA.click();
        }else {
            if (a.request.responseURL && a.request.responseURL.indexOf("up.qiniu.com") != -1) {
                if (!a.data.hash) {
                    definedPrompt('上传失败，刷新页面后重新上传', function(){
                        //location.reload();
                    }, {cencalFlag: hide});
                }
            } else {
                if (a.data.flag) {
                    if (a.data.flag == -1) {
                        //definedToast(a.data.msg, '', {cancelFlag: hide});
                        ELEMENT.Message.error(a.data.msg);
                        //ELEMENT.$message.error('simida')
                    }
                } else {

                }
            }
        }
    }
    return a;
}, function(err){
    //definedPrompt(err, '', {cancelFlag: hide});
});


const router = new VueRouter({
  hashbang: false,
  //base: '/webapp',
  mode: 'history',
  routes: configRouter
});
G.router = router;

G.mixinMethods = {
    methods: {
        goto: function(u){
            if(!u) return ;
            location.assign(u);
        },
        gotoName: function(name){
            if(!name) return ;
            router.push({name: name});
        },
        gotoPath: function(path){
            if(!path) return ;
            router.push(path);
        }
    }
}


new Vue({
    data: {
    },
    methods: {
        goto: function(){
        }
    },
    store,
    router,
    render: h => h(App)
}).$mount('#app')
